#include <stdlib.h>
#include <stdio.h>
#include <iostream>

using namespace std;

class top
{
public:
	top()
	{
		top_num = 1;
	}
	int top_num;
};


class left:virtual public top
{
public:
	left()
	{
		left_num = 2;
	}
	int left_num;
};


class right:virtual public top
{
public:
	right()
	{
		right_num = 3;
	}
	int right_num;
};


class bottom:public left, public right
{
public:
	bottom()
	{
		bottom_num = 4;
	}
	int bottom_num;
	//int c;
};


int main(int argc, char**argv)
{
	cout << sizeof(class top) << '\t' << sizeof(class left) << '\t' << sizeof(class right) << '\t' << sizeof(class bottom) << endl;
 	
	class left* pleft = new class left();
	cout << "class left: " << pleft << "\ttop: " << &pleft->top_num << "\tleft: " << &pleft->left_num << endl;

	class right* pright = new class right();
	cout << "class right: " << pright << "\ttop: " << &pright->top_num << "\tleft: " << &pright->right_num << endl;

	bottom* pbottom = new bottom();
	cout << "class bottom:"  << pbottom << "\tleft top: " << &pbottom->left::top_num << "\tleft: " << &pbottom->left_num << " \tright top: " << &pbottom->right::top_num << "\tright: " << &pbottom->right_num << "\tbottom: " << &pbottom->bottom_num << endl;

	delete pleft;
	delete pright;

	pleft = pbottom;
	cout << "class bottom: " << pbottom << "\tpleft: " << pleft << endl;
	
	pright = pbottom;
	cout << "class bottom: " << pbottom << "\tpright: " << pright << endl;

	class top* ptop = pbottom;
	cout << "class bottom: " << pbottom << "\tptop: " << ptop << endl;
	
	cout << "unknow field: " << *(int*)(((char*)pleft) + 12) << endl;
	
	return 0;
}
